package com.bw1806.sellergoods.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.bw1806.mapper.TbSpecificationMapper;
import com.bw1806.pojo.TbSpecification;
import com.bw1806.pojo.TbSpecificationExample;
import com.bw1806.sellergoods.service.TbSpecificationService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import entity.PageResult;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @描述
 * @创建人 wangyue
 * @创建时间2020/11/1115:02
 */
@Service(timeout = 5000,retries = 0)
public class TbSpecificationServiceImpl implements TbSpecificationService {

    @Autowired
    private TbSpecificationMapper tbSpecificationMapper;

    @Override
    public List<TbSpecification> findAll() {
        return tbSpecificationMapper.selectByExample(null);
    }

    @Override
    public PageResult<TbSpecification> pagelist(TbSpecification tbSpecification,int pageNum,int pageSize) {

        PageHelper.startPage(pageNum, pageSize);

        TbSpecificationExample example=new TbSpecificationExample();

        TbSpecificationExample.Criteria criteria = example.createCriteria();

        if(tbSpecification!=null){
            //if(tbSpecification.getName()!=null && tbSpecification.getName().length()>0){
            //    criteria.andNameLike("%"+tbSpecification.getName()+"%");
           // }
        }

        Page<TbSpecification> page= (Page<TbSpecification>) tbSpecificationMapper.selectByExample(example);

        return new PageResult(page.getTotal(), page.getResult());
    }

    @Override
    public void save(TbSpecification tbSpecification) {
        Long id = tbSpecification.getId();
        if(id != null && id !=0){
            tbSpecificationMapper.updateByPrimaryKey(tbSpecification);
        } else{
            tbSpecificationMapper.insert(tbSpecification);
        }
    }

    @Override
    public TbSpecification getById(Long id) {
        return tbSpecificationMapper.selectByPrimaryKey(id);
    }

    @Override
    public void deletebth(Long[] ids) {
       for(long id : ids){
            tbSpecificationMapper.deleteByPrimaryKey(id);
        }
        //tbSpecificationMapper.deletebth(ids);
    }
}
